document.ready(function () {

  //身份实名认证购买栏选项按钮功能
  let choiceItemFun = function () {
    /**
* 1.需求: 定义价格数据
*/
    let pricData = [
      {
        count: 4000,
        price: 1200,
        unitPrice: 0.3000
      },
      {
        count: 8000,
        price: 2000,
        unitPrice: 0.2500
      },
      {
        count: 40000,
        price: 8000,
        unitPrice: 0.2000
      },
    ];

    /**
   * 2.需求: 将价格数据渲染到页面中
   */
    //获取元素
    let choiceItem = document.querySelector('.choice')

    let countStr = '';
    pricData.forEach(function (v) {
      countStr += `<span class="count" data-t-price='${v.price}' data-u-price='${v.unitPrice}' data-flag="true">${v.count}次<i></i></span>`
    })
    choiceItem.innerHTML += countStr;

    /**
    * 3.需求: 点击.count按钮,添加激活样式,.priceExplain2对应的数据渲染显示
    */
    //获取元素
    let tPrice = document.querySelector('.priceExplain2 .tPrice');
    let uPrice = document.querySelector('.priceExplain2 i');
    let countAll = document.querySelectorAll('.choice .count');
    let index = 0;
    let num;

    countAll.forEach(function (v, i) {
      v.num = i;
    })
    choiceItem.addEventListener('click', function (event) {
      let target = event.target;
      if (target.className.toLowerCase() === 'count') {
        countAll[index].classList.remove('active');
        target.classList.add('active');

        tPrice.textContent = target.dataset.tPrice;
        uPrice.textContent = (+target.dataset.uPrice).toFixed(4);
        index = target.num;
      }
    })
  }
  choiceItemFun();



  // Tab栏切换功能
  let tabP = document.querySelector('.tabChange .tabC');
  let allSubTab = tabP.querySelectorAll('p');
  let allTabC = document.querySelectorAll('.tabContent>.cLeft>div');
  tabCard(tabP, 'P', allSubTab, 'active', allTabC, 'tabSwitch');

})